package com.example.spring.demo.mapper;

import com.example.spring.demo.entity.UserToken;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/31 14:59
 **/
@Mapper
public interface TokenMapper {
    @Insert("""
insert into user_token (user_id, token_key, token) values (#{userId}, #{tokenKey}, #{token});
""")
    void saveToken(UserToken userToken);

    @Select("""
select token from user_token where token_key = #{tokenKey};
""")
    String getToken(String tokenKey);

    @Delete("""
delete from user_token where user_id = #{userId} and token = #{token} and token_key = #{userToken};
""")
    int delUerToken(UserToken userToken);

    @Delete("""
delete from user_token where user_id = #{userId};
""")
    int delUserToken(Integer userId);
}
